package com.example.demoday.service.impl;

import com.example.demoday.mapper.UserMapper;
import com.example.demoday.pojo.User;
import com.example.demoday.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public void add(User user) {
        user.setCreateTime(LocalDateTime.now());
        user.setUpdateTime(LocalDateTime.now());

        userMapper.add(user);
    }

    @Override
    public void del(int id) {
        userMapper.del(id);
    }

    @Override
    public void update(User user) {
        user.setUpdateTime(LocalDateTime.now());

        userMapper.update(user);
    }

    @Override
    public User detail(int id) {
        User user = userMapper.detail(id);

        return user;
    }

    @Override
    public List<User> findByName(String name) {
        return userMapper.findByName(name);
    }

    @Override
    public List<User> findByEmail(String email) {
        return userMapper.findByEmail(email);
    }

    @Override
    public List<User> findAll(int offset, int limit) {
        return userMapper.findAll(offset, limit);
    }
}